import { ipcApiRoute } from '@/service/ee';
import { ipc } from '@/utils/ipc';

// 拖拽移动
let moveIng = false;
let startX = 0;
let startY = 0;
let lastWidth = 0;
let lastHeight = 0;

// 拖拽移动
function move(event: any) {
  if (!moveIng) return;
  const x = window.screenX + event.clientX - startX;
  const y = window.screenY + event.clientY - startY;
  ipc.invoke(ipcApiRoute.moveWindow, { x, y, width: lastWidth, height: lastHeight });
}

export function addListenerDragEEMouseDown(event: any) {
  // 绑定拖拽移动事件
  moveIng = true;
  startX = event.clientX;
  startY = event.clientY;
  lastWidth = window.outerWidth;
  lastHeight = window.outerHeight;
  document.addEventListener('mousemove', move);
}

export function removeListenerDragEEMouseDown() {
  // 解除拖拽移动事件
  if (!moveIng) return;
  document.removeEventListener('mousemove', move);
  moveIng = false;
}
